// pages/my/my-statistics/index.js
const controllers = require('../../controllers/controllerOrder').controller
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    total: {},
    date: '本月',
    settlement: '',
    list: [],
    upimg: '/images/dianyuan/on_line_icon_01@2x.png',
    dowmimg: '/images/dianyuan/offline_icon_01@2x.png',
    pageNumber: 1,
    pageSize: 20,
    isEnd: false,
    time: '',
    commission:0,
    balance:0,
    all:0,
    upPrice:0,
    lowPrice:0,
    payPrice:0
  },
  //选择时间
  choicedate(e) {
    this.setData({
      date: e.detail.value,
      pageNumber: 1,
      pageSize: 20,
      isEnd: false,
      list: []
    })
    this.list(this.data.date)
  },
  //获取列表
  list(time) {
    controllers.shopStaffList({
      shopId: wx.getStorageSync('shopId'),
      time: time,
      pageNumber: this.data.pageNumber,
      pageSize: this.data.pageSize
    }).then(res => {
      console.log(res);
      this.setData({
        commission:res.data.commission
      })
      if (res.data.page.list.length != 0) {
        this.setData({
          list: this.data.list.concat(res.data.page.list)
        })
      }
      if (res.data.page.lastPage) {
        this.setData({
          isEnd: true
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    controllers.shopStaffTotal({
      shopId: wx.getStorageSync('shopId')
    }).then(res => {
      console.log(res);
      this.setData({
        total: res.data,
        balance:(res.data.lowPrice+res.data.upPrice-res.data.payPrice).toFixed(2),
        all:(res.data.lowPrice+res.data.upPrice).toFixed(2),
        upPrice:res.data.upPrice.toFixed(2),
        lowPrice:res.data.lowPrice.toFixed(2),
        payPrice:res.data.payPrice.toFixed(2)
      })
    })
    var date = new Date();
    var year = date.getFullYear();
    var month = parseFloat(date.getMonth()) + 1
    this.setData({
      time: year + '-' + month
    })
    this.list(year + '-' + month)


  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.isEnd) {
      return;
    } else {
      this.setData({
        pageNumber: this.data.pageNumber + 1,
      });
      this.list(this.data.time)
    }
  },

  /**
   * 用户点击右上角分享
   */
   // onShareAppMessage: function () {

  // }
})